#region File Header
//----------------------------------------------------------------
// Copyright (C) 2002 Stefan Kyntchev
// All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
// FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------
#endregion File Header

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using AirWeb.ApplicationTools.Common;
using AirWeb.DirectoryMgr;
using AirWeb.Security;
using AirWeb.ApplicationTools;

namespace FlashBack.Web
{
	/// <summary>
	/// Summary description for FilmStrip.
	/// </summary>
	public partial class DetailList : ThumbNails
	{

		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		/// <summary>
		/// Displays an error message in the middle of the screen
		/// </summary>
		/// <param name="i_msg"></param>
		override protected void DisplayErrorMsg(string i_msg)
		{
			MsgLabel.Visible = true;
			MsgLabel.Text = i_msg;
		}

		override protected void SetTitle(string i_newTitle)
		{
			detailstitle.Text = i_newTitle;
		}

		override protected void SetNavigation(string i_newTitle, string i_newURL)
		{
			detailstitle.Text = i_newTitle;

			if(CurrentUser.IsAdministrator())
			{
				attributeLink.Visible = true;

				if(i_newURL != "")
					attributeLink.NavigateUrl = "AttributeEditor.aspx?" + i_newURL;
				else
					attributeLink.Visible = false;
			}
		}

		override protected DirectoryHelper.FolderType GetFolderType()
		{
			return DirectoryHelper.FolderType.org;
		}

		override protected void BuildAndBind()
		{
			DataTable dt = new DataTable();
			DataRow dr;
			dt.Columns.Add(new DataColumn("tnpath", typeof(string)));
			dt.Columns.Add(new DataColumn("Name", typeof(string)));
			dt.Columns.Add(new DataColumn("DateTaken", typeof(DateTime)));
			dt.Columns.Add(new DataColumn("Size", typeof(string)));
			dt.Columns.Add(new DataColumn("download", typeof(string)));

			System.Collections.IEnumerator myEnumerator = m_contentList.GetEnumerator();

			while ( myEnumerator.MoveNext() )
			{
				dr = dt.NewRow();

				FileInfo f = (FileInfo)myEnumerator.Current;
				
				string ogvp = m_dirHelper.ReverseMapPath(f.FullName,m_dirHelper.OriginalsVirtualRoot);
				
				dr[0] = ogvp;
				dr[1] = f.Name;
				dr[2] = f.CreationTime;
					
				long filesize;
				
				if(f.Exists)
					filesize = f.Length / 1024;
				else
					filesize = 3000 / 1024;

				dr[3] = filesize.ToString() + " K";
				
				dr[4] = ogvp;

				dt.Rows.Add(dr);
			}

			DataView v = new DataView(dt);
			v.Sort = "DateTaken DESC";
			DetailsGrid.DataSource = v;
			DetailsGrid.DataBind();
		}

		protected new void onRowBound(object sender, DataGridItemEventArgs e)
		{
			if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
			{
				System.Web.UI.WebControls.Image i = new System.Web.UI.WebControls.Image();

				string path = e.Item.Cells[0].Text;
				path = m_dirHelper.OG2TN(path);

				if(!CommonHelper.IsMovie(path))
				{
					i.ImageUrl = path;
					i.Width = new Unit("30px");
					i.Height = new Unit("30px");
				}
				else
					i.ImageUrl = "images/movie.gif";

				e.Item.Cells[0].Controls.Clear();
				e.Item.Cells[0].Controls.Add(i);

				HyperLink h = new HyperLink();
				h.Text = "Download";
				h.ToolTip = "To download this movie right click and select 'Save Target As...'";
				h.Target = "_new";
				h.NavigateUrl = e.Item.Cells[4].Text; 

				e.Item.Cells[4].Controls.Clear();
				e.Item.Cells[4].Controls.Add(h);
			}
		}

		protected new void ChangePageIndex(object Sender, DataGridPageChangedEventArgs e)
		{
			DetailsGrid.CurrentPageIndex = e.NewPageIndex;
			BuildAndBind();
		}
	}
}
